package com.imooc.forkcgz;

import java.math.BigInteger;

/**
 * Created by xyb on 2017/1/11.
 */

public class FibonacciUtils {
    public static BigInteger fibonacci(int num) {
        BigInteger one, two, three;
        one = BigInteger.ZERO;
        two = three = BigInteger.ONE;
        if (num == 0) {
            return BigInteger.ZERO;
        } else if (num <= 2) {
            return BigInteger.ONE;
        } else {
            for (int i = 3; i <= num; i++) {
                one = two.add(three);
                two = three;
                three = one;
            }
            return one;
        }


    }

}
